// JavaScript Document
var filter  = /^([a-zA-Z0-9_\.\-]{7,11})+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var phone   = $('input[name="phone"]'),
	pass    = $('input[name="pass"]'),
	repass  = $('input[name="repass"]'),
	company = $('input[name="company"]'),
	id_img  = $('#id_img');

function radioShow(id){
	var company = $('#company'),
		code = $('#code');

	phone.val('');
	pass.val('');
	repass.val('');
	company.val('');
	id_img.attr('src','images/add_image.png');

	if(id==1){
		company.hide();
		code.hide();
	}else if(id==2){
		company.show();
		code.hide();
	}else if(id==3){
		company.show();
		code.show();
	}

	$('input[type="button"]').attr('onclick','zhuce('+id+')');
}
//图片格式	
$("#test_file").change(function(){
    var file = this.files[0];
    if(!/image\/\w+/.test(file.type)){
        alert("请确保文件为图像类型");
        return false;
    }
    var reader = new FileReader();
    
    reader.readAsDataURL(file);                    
    reader.onload = function(e){
        $('#id_img').attr('src',this.result);
    }
});
//注册
function zhuce(id){

	if(id == 1){
		if(phone.val()==""){

			PromptHide('请输入邮箱/手机');
			phone.focus();

		}else if( !(phone.val().match(/^1[3|4|5|8][0-9]\d{8}$/) || filter.test(phone.val())) ){

			PromptHide('请输入信息有误');
			phone.focus();

		}else if(pass.val()=="" || pass.val().length < 6){

			PromptHide('密码最少6位字符');
			pass.focus();

		}else if(repass.val()=="" || repass.val() != pass.val()){

			PromptHide('密码输入不一致');
			repass.focus();

		}else if(!$(".xie-yi").is(':checked')){
			PromptHide("请同意协议");return
		}else{
			submit();
		}
	}
	if(id == 2){
		if(phone.val()==""){

			PromptHide('请输入邮箱/手机');
			phone.focus();

		}else if( !(phone.val().match(/^1[3|4|5|8][0-9]\d{8}$/) || filter.test(phone.val())) ){

			PromptHide('请输入信息有误');
			phone.focus();

		}else if(pass.val()=="" || pass.val().length < 6){

			PromptHide('密码最少6位字符');
			pass.focus();

		}else if(repass.val()=="" || repass.val() != pass.val()){

			PromptHide('密码输入不一致');
			repass.focus();

		}else if(company.val()==""){
			PromptHide('请填写公司名称');
			company.focus();

		}else if(!$(".xie-yi").is(':checked')){
			PromptHide("请同意协议");return
		}else{
			submit();
		}
	}
	if(id == 3){
		if(phone.val()==""){

			PromptHide('请输入邮箱/手机');
			phone.focus();

		}else if( !(phone.val().match(/^1[3|4|5|8][0-9]\d{8}$/) || filter.test(phone.val())) ){

			PromptHide('请输入信息有误');
			phone.focus();

		}else if(pass.val()=="" || pass.val().length < 6){

			PromptHide('密码最少6位字符');
			pass.focus();

		}else if(repass.val()=="" || repass.val() != pass.val()){

			PromptHide('密码输入不一致');
			repass.focus();

		}else if(company.val()==""){
			PromptHide('请填写公司名称');
			company.focus();
			return false;

		}else if(id_img.attr('src')=="images/add_image.png"){
			PromptHide('请上传图片')

		}else if(!$(".xie-yi").is(':checked')){
			PromptHide("请同意协议");
			return false;
		}else{
			submit();
		}
	}	
}

function submit(){
	PromptHide('注册成功');
}


function input(){
	if(phone.val().match(/^1[3|4|5|8][0-9]\d{8}$/) || filter.test(phone.val())){
		//alert('格式正确');
	}else{
		PromptHide('格式不正确');
		return
	}
	
}

function mima(){
	if(pass.val().length<6){
		PromptHide('字符不能少于6个字符');
	}
};
function test(){

	if(pass.val() == repass.val()){
		PromptHide("密码一致");
	}else{
		PromptHide("密码输入不一致");
	}
}

PromptHide();

function PromptHide(msg){

    var prompt = $('.prompt');
    if(0 == prompt.length){//如果不存在,则创建一个
        $('body').append('<div class="prompt"></div>');
        prompt = $('.prompt');
    }
    if(prompt){
        msg && prompt.html(msg).fadeIn();
        setTimeout(function(){prompt.fadeOut()},2000);
    }

}